/**
 *	\file
 *	\brief represents a single cell in the hash table storing function resources.
 *
 * 	\date Sep 20, 2013
 * 	\author koldar
 *	\version 1.0
 */

#ifndef LOCALRESOURCEHTCELL_H_
#define LOCALRESOURCEHTCELL_H_

#include "LocalResourceElement.h"
#include "uthash.h"

/**indicates a single HashTable containing LocalResource elements
 *
 */
typedef struct LocalResourceHTCell {
	const char* key; //!< points to the location where the name of localResource is stored
	PlocalResourceElement localResource; //!< points to the localResource stored itself
	UT_hash_handle hh;
} LocalResourceHTCell;

/**pointer to a cell
 *
 */
typedef LocalResourceHTCell* PlocalResourceHTCell;

/**initialize correctly an hashtable cell. It can be freed with freeLocalResourceHTCell().
 *
 * \pre
 *  \li _localResource not NULL
 * \post
 *  \li a new element of the hash table that can be added to it;
 *  \li the key of this element points to the field "name" of the localResource set as value
 *
 * @param _localResource the structure to be decorated to be am hash table cell
 * @return a pointer to the newly created LocalResourceHTCell
 */
PlocalResourceHTCell initLocalResourceHTCell(PlocalResourceElement _localResource);

/**Frees correctly a hash table cell
 *
 * \pre
 *  \li pcell must not be NULL
 * \post
 *  \li pcell is correctly freed from memory
 *
 * @param pcell the cell to be deallocated
 */
void freeLocalResourceHTCell(PlocalResourceHTCell pcell);

/**print a string representation of this hash table cell
 *
 * \pre
 *  \li f open in write mode;
 *  \li pcell not NULL;
 * \post
 *  \li f changed;
 *  \li in f the cell is represented by the expression: "[ key -> value ]"
 *
 * @param f the file to write on
 * @param pcell the cell to write
 */
void printLocalResourceHTCell(FILE* f,PlocalResourceHTCell pcell);

/**writes in f a code block that can be interpreted as a node in DOT language.
 * This function should be used to automatically generate DOT file representing
 * a local resource hash table.
 *
 * \pre
 *  \li f open in write mode;
 * \post
 *  \li in f there is a piece of code <b>not</b> immidiately compilable by dot;
 *  \li in f there is a piece of code representing this cell;
 *  \li the nodenumber is increase of 1 unit
 *
 *
 * @param f the file to write on
 * @param pcell the cell to write
 * @param nodenumber the number of the dot node identifier. For example if you pass 53 then the ID will be n053. The regex is n%03d
 * @param cellnumber represents the number of the cell generated by this function
 * @param format represents the number of '\t' characters to be put before every line generated by this function
 */
void generateDOTLocalResourceHTCell(FILE* f,PlocalResourceHTCell pcell,int* nodenumber,int* cellnumber,int format);

#endif /* LOCALRESOURCEHTCELL_H_ */
